package com.cy.pj.sys.service.impl;

import com.cy.pj.common.exception.ServiceException;
import com.cy.pj.common.pojo.PageObject;
import com.cy.pj.sys.dao.SysUserDao;
import com.cy.pj.sys.pojo.SysUser;
import com.cy.pj.sys.service.SysUserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    private SysUserDao sysUserDao;
    public int validById(Integer id,Integer valid){
        int rows=sysUserDao.validById(id,valid);
        if(rows==0)throw new ServiceException("记录可能已经不存在");
        return rows;
    }

    public PageObject<SysUser> findPageObjects(String username,
                                               Integer pageCurrent){
        int pageSize=5;
        Page<SysUser> page= PageHelper.startPage(pageCurrent,pageSize);
        List<SysUser> records=sysUserDao.findPageObjects(username);
        return new PageObject((int)page.getTotal(),records,
                pageSize,pageCurrent);
    }
}
